/*
 * Copyright (C) 2016 alchemystar, Inc. All Rights Reserved.
 */
package live.sidian.database.synchronizer.sync.structure;


import live.sidian.database.synchronizer.infrastructure.sql.SqlCreator;
import live.sidian.database.synchronizer.sync.structure.model.Database;
import live.sidian.database.synchronizer.sync.structure.model.Table;
import lombok.*;
import lombok.experimental.SuperBuilder;

import java.util.LinkedList;
import java.util.List;

/**
 * 数据库元数据
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class MetaData extends Database {
    /**
     * 该表是否存在
     */
    @Builder.Default
    boolean exist = true;
    /**
     * 所有的表
     */
    @Builder.Default
    List<Table> tables = new LinkedList<>();

    public List<String> toSql() {
        List<String> list = new LinkedList<>();
        list.add(SqlCreator.createDatabase(getSchema(), getCharset()));
        tables.forEach(table -> list.add(table.getCreateSql()));
        return list;
    }
}
